package com.atguigu.ssyx.common.exception;

import com.atguigu.ssyx.common.result.ResultCodeEnum;
import lombok.Data;

/**
 * @author 杨林
 * @create 2023-07-04 22:20 星期二
 * description:自定义异常类
 */
public class SsyxException extends RuntimeException {

    //状态码
    private Integer code;

    /**
     * 通过状态码和异常信息构建自定义异常类
     */
    public SsyxException(Integer code,String message){
        super(message);  //注意：super关键字应该放在第一行
        this.code = code;
    }

    /**
     * 通过枚举构建异常对象
     * @param resultCodeEnum
     */
    public SsyxException(ResultCodeEnum resultCodeEnum){
        super(resultCodeEnum.getMessage());  //注意：super关键字应该放在第一行
        this.code = resultCodeEnum.getCode();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    @Override
    public String toString() {
        return "SsyxException{" +
                "code=" + code +
                "message=" + this.getMessage() +
                '}';
    }
}
